// node  --trace-gc --expose-gc --max-heap-size=100 --no-compilation-cache client1.js
// 老内存异常搞不定
const https = require('https')
const fs = require('fs')
const path = require('path')
const json = JSON.stringify({ id: '111', name: 'js client1' })
const options = {

  pfx: fs.readFileSync(path.join(__dirname, 'config', 'ca', 'client', 'client.pfx')),
  passphrase: '654321',
  //   key: fs.readFileSync('./certificate/client-key.pem'),
  //   cert: fs.readFileSync('./certificate/client.pem'),
  //
  ca: [fs.readFileSync(path.join(__dirname, 'config', 'ca', 'client', 'server.crt'))],
  agent: false,
  // 开启双向认证
  rejectUnauthorized: true,
  // ----
  hostname: '192.168.1.189',
  port: 8082,
  path: '/demo/post/hello',
  method: 'POST',
  json: true,
  headers: {
    'Content-Type': 'application/json'
    // ,'Content-Length': json.length
  }
}

const req = https.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`)
  res.setEncoding('utf8')
  res.on('data', (d) => {
    process.stdout.write(d)
    console.log(d)
  })
})

req.on('error', (error) => {
  console.error(error)
})

req.write(json)
req.end()
console.log('-----------end')
